#ifndef TRACE_HPP
#define TRACE_HPP
#include <iostream>
#include <sstream>
#include <string>

extern std::ostream *traceOutput;
extern std::string traceOutputName;

void setAlwaysTrace(bool enabled);
void initTrace();

class TraceStream
{
public:
	TraceStream();
	
	template<class T>
	TraceStream &operator<< (const T &element)
	{
		if(directToStdout) {
			if(!traceOutput)
				initTrace();
			(*traceOutput) << element << std::flush;
		} else {
			buf << element;
		}
		return *this;
	}
	
	void flush();
	void clear();
	void close();
	
	std::stringstream buf;
	bool directToStdout;
};
extern TraceStream trace;

#endif
